using System;
using System.Collections.Generic;
using System.Text;

using System.Management.Automation;

namespace Microsoft.PowerShell.CmdletManagement
{
    [Cmdlet(VerbsCommon.Set, "PsSpecCmdletParameterSetEntry", SupportsShouldProcess = true)]
    public class SetPsSpecCmdletParameterSetEntryCommand : PsSpecCommandBase
    {
        [Parameter(Mandatory = true, ValueFromPipelineByPropertyName=true)]
        public int Id
        {
            get { return parameterSetEntryId; }
            set { parameterSetEntryId = value; }
        }
        private int parameterSetEntryId = 0;

        [Parameter(ValueFromPipelineByPropertyName = true)]
        [AllowNull]
        [AllowEmptyString]
        public string ParameterSetName
        {
            get { return parameterSetName; }
            set
            {
                if ((value != null) && (value.Length > 50))
                    throw new ArgumentOutOfRangeException("ParameterSetName");

                parameterSetName = value;
            }
        }
        private string parameterSetName = null;

        [Parameter(ValueFromPipelineByPropertyName = true)]
        [AllowNull]
        public bool? Mandatory
        {
            get { return mandatory; }
            set { mandatory = value; }
        }
        private bool? mandatory;

        [Parameter(ValueFromPipelineByPropertyName = true)]
        [AllowNull]
        public int? Position
        {
            get { return position; }
            set
            {
                if (value == null)
                {
                    position = -1;
                }
                else
                {
                    position = value;
                }
            }
        }
        private int? position;

        [Parameter(ValueFromPipelineByPropertyName = true)]
        [AllowNull]
        public bool? ValueFromPipeline
        {
            get { return valueFromPipeline; }
            set { valueFromPipeline = value; }
        }
        private bool? valueFromPipeline;

        [Parameter(ValueFromPipelineByPropertyName = true)]
        [AllowNull]
        public bool? ValueFromPipelineByPropertyName
        {
            get { return valueFromPipelineByPropertyName; }
            set { valueFromPipelineByPropertyName = value; }
        }
        private bool? valueFromPipelineByPropertyName;

        [Parameter(ValueFromPipelineByPropertyName = true)]
        [AllowNull]
        public bool? ValueFromRemainingArguments
        {
            get { return valueFromRemainingArguments; }
            set { valueFromRemainingArguments = value; }
        }
        private bool? valueFromRemainingArguments;

        [Parameter(ValueFromPipelineByPropertyName = true)]
        [AllowNull]
        [AllowEmptyString]
        public string HelpMessage
        {
            get { return helpMessage; }
            set
            {
                if ((value != null) && (value.Length > 200))
                    throw new ArgumentOutOfRangeException("HelpMessage");

                helpMessage = value;
            }
        }
        private string helpMessage;

        [Parameter(ValueFromPipelineByPropertyName = true)]
        [AllowNull]
        [AllowEmptyString]
        public string HelpMessageBaseName
        {
            get { return helpMessageBaseName; }
            set
            {
                if ((value != null) && (value.Length > 200))
                    throw new ArgumentOutOfRangeException("HelpMessageBaseName");

                helpMessageBaseName = value;
            }
        }
        private string helpMessageBaseName;

        [Parameter(ValueFromPipelineByPropertyName = true)]
        [AllowNull]
        [AllowEmptyString]
        public string HelpMessageResourceId
        {
            get { return helpMessageResourceId; }
            set
            {
                if ((value != null) && (value.Length > 200))
                    throw new ArgumentOutOfRangeException("HelpMessageResourceId");

                helpMessageResourceId = value;
            }
        }
        private string helpMessageResourceId;

        protected override void ProcessRecord()
        {
            if (ShouldProcess(
                String.Format("{0}", ServiceUri),
                String.Format(resources.SetPsSpecCmdletParameterSetEntry, Id)))
            {
                try
                {
                    Service.UpdatePsSpecCmdletParameterSetEntry(Id, Mandatory, Position, ParameterSetName, ValueFromPipeline,
                        ValueFromPipelineByPropertyName, ValueFromRemainingArguments, HelpMessage, HelpMessageBaseName,
                        HelpMessageResourceId);
                }
                catch (System.Web.Services.Protocols.SoapException e)
                {
                    WriteError(new ErrorRecord(e, "CMDLET_SERVICE_ERROR",
                                                ErrorCategory.InvalidOperation,
                                                String.Format(resources.SetPsSpecCmdletParameterShouldProcess, Id)));
                }
            }
        }
    }
}
